//
//  MovieDetailViewController.m
//  豆瓣
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailViewController.h"
#import "MovieDetailView.h"
#import "AppTools.h"
#import "UIImageView+WebCache.h"
#import "SDImageCache.h"
#import "Movie.h"

@interface MovieDetailViewController ()

@property (nonatomic, retain)MovieDetailView *movieDV;

@end

@implementation MovieDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    scroll.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:scroll];
    
    [scroll release];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_share.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)];
    
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.movieDV = [[MovieDetailView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    [scroll addSubview:self.movieDV];
    
    [self.movieDV release];
    
    NSString *urlStr = [NSString stringWithFormat:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/searchmovie.php?movieId=%@", self.movieID];
    
    [AppTools getDataWithURL:urlStr block:^(id result) {
        
        NSMutableDictionary *dic = result;
        
        NSDictionary *resultDic = [dic objectForKey:@"result"];
        
        self.navigationItem.title = [resultDic objectForKey:@"title"];
        
        self.movieDV.rating.text = [resultDic objectForKey:@"rating"];
        
        self.movieDV.rating_count.text = [NSString stringWithFormat:@"(%@条评论)", [resultDic objectForKey:@"rating_count"]];
        
        self.movieDV.runtime.text = [resultDic objectForKey:@"runtime"];
        
        self.movieDV.genres.text = [resultDic objectForKey:@"genres"];
        
        self.movieDV.release_date.text = [resultDic objectForKey:@"release_date"];
        
        self.movieDV.country.text = [resultDic objectForKey:@"country"];
        
        self.movieDV.actors.text = [resultDic objectForKey:@"actors"];
        
        self.movieDV.plot_simple.text = [resultDic objectForKey:@"plot_simple"];
        
        [self.movieDV.plot_simple sizeToFit];
        
        CGFloat height = self.movieDV.plot_simple.frame.origin.y + self.movieDV.plot_simple.frame.size.height + 64;
        
        [scroll setContentSize:CGSizeMake(375, height)];
        
        NSURL *url = [NSURL URLWithString:[resultDic objectForKey:@"poster"]];
        
        [self.movieDV.headImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
        
    }];

    
}

- (void)buttonAction:(UIBarButtonItem *)btn
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
